package qrcodeUtils

import (
	"github.com/skip2/go-qrcode"
	"image"
	"image/color"
	"image/draw"
	"image/jpeg"
	"image/png"
	"os"
)

func main() {
	//qrcode.WriteFile("https://blog.csdn.net/yang731227",qrcode.High,200,"./qrcode.png")
	qrcode.WriteColorFile("https://blog.csdn.net/yang731227", qrcode.Medium, 256, color.Black, color.White, "./qrcode.png")
	imgb, _ := os.Open("./qrcode.png")
	img, _ := png.Decode(imgb)
	defer imgb.Close()

	wmb, _ := os.Open("out.jpg")
	watermark, _ := jpeg.Decode(wmb)
	defer wmb.Close()
	offset := image.Pt((img.Bounds().Dx()-watermark.Bounds().Dx())/2, (img.Bounds().Dy()-watermark.Bounds().Dy())/2)
	b := img.Bounds()
	m := image.NewNRGBA(b)

	draw.Draw(m, b, img, image.ZP, draw.Src)
	draw.Draw(m, watermark.Bounds().Add(offset), watermark, image.ZP, draw.Over)
	imgw, _ := os.Create("new.jpg")
	jpeg.Encode(imgw, m, &jpeg.Options{Quality: 100})
	defer imgw.Close()

}
